package ua.com.alus.resvac.crm.domen.entities;

import ua.com.alus.resvac.crm.domen.prototype.Education;
import ua.com.alus.resvac.crm.domen.prototype.Experience;
import ua.com.alus.resvac.crm.domen.prototype.SexType;
import ua.com.alus.resvac.crm.domen.prototype.Status;
import ua.com.alus.resvac.crm.domen.prototype.TypeOfEmployment;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.List;

/**
 * Created by Usatov Alexey
 */
@Entity
@Table(name = "VACANCY")
@NamedQueries({
        @NamedQuery(name = Vacancy.SELECT_VACANCY_BY_ACCOUNT_UUID, query = "select v from Vacancy v where accountUUID=:accountUuid")
})
public class Vacancy extends BaseEntity implements Serializable {
    public static final String SELECT_VACANCY_BY_ACCOUNT_UUID = "ua.com.alus.resvac.crm.domen.entities.Vacancy.selectVacancyByUuid";

    @ManyToOne
    @JoinColumn(name = "FK_ACCOUNT_UUID", referencedColumnName = "PK_UUID")
    private Account account;

    @Column(name = "FK_ACCOUNT_UUID", insertable = false, updatable = false)
    public String accountUUID;

    @Column(name = "POSITION")
    private String position;

    @OneToOne
    @JoinColumn(name = "FK_PROF_AREA_UUID", referencedColumnName = "PK_UUID", insertable = false, updatable = false)
    private ProfessionArea professionArea;

    @OneToOne
    @JoinColumn(name = "FK_CITY_ID", referencedColumnName = "ID", insertable = false, updatable = false)
    private City city;

    @OneToMany(mappedBy = "vacancy", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List<VacancyFile> vacancyFiles;

    @Column(name = "FK_PROF_AREA_UUID")
    private String fkProfAreaUuid;

    @Column(name = "FK_CITY_ID")
    private Integer fkCityId;

    @Column(name = "FK_REGION_ID")
    private Integer fkRegionId;

    @Column(name = "SALARY")
    private String salary;

    @Column(name = "SEX")
    @Enumerated(value = EnumType.STRING)
    private SexType sex;

    @Column(name = "EXPERIENCE")
    @Enumerated(value = EnumType.STRING)
    private Experience experience;

    @Column(name = "TYPE_EMPLOYMENT")
    @Enumerated(value = EnumType.STRING)
    private TypeOfEmployment typeOfEmployment;

    @Column(name = "DESCRIPTION")
    private String description;

    @Column(name = "CONTACTS")
    private String contacts;

    @Column(name = "STATUS")
    @Enumerated(value = EnumType.STRING)
    private Status status;

    @Column(name = "EDUCATION")
    @Enumerated(value = EnumType.STRING)
    private Education education;

    @Column(name = "AGE")
    private String age;

    public Account getAccount() {
        return account;
    }

    public void setAccount(Account account) {
        this.account = account;
    }

    public String getAccountUUID() {
        return accountUUID;
    }

    public void setAccountUUID(String accountUUID) {
        this.accountUUID = accountUUID;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public ProfessionArea getProfessionArea() {
        return professionArea;
    }

    public String getFkProfAreaUuid() {
        return fkProfAreaUuid;
    }

    public void setFkProfAreaUuid(String fkProfAreaUuid) {
        this.fkProfAreaUuid = fkProfAreaUuid;
    }

    public Integer getFkCityId() {
        return fkCityId;
    }

    public void setFkCityId(Integer fkCityId) {
        this.fkCityId = fkCityId;
    }

    public Integer getFkRegionId() {
        return fkRegionId;
    }

    public void setFkRegionId(Integer fkRegionId) {
        this.fkRegionId = fkRegionId;
    }

    public String getSalary() {
        return salary;
    }

    public void setSalary(String salary) {
        this.salary = salary;
    }

    public SexType getSex() {
        return sex;
    }

    public void setSex(SexType sex) {
        this.sex = sex;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getContacts() {
        return contacts;
    }

    public void setContacts(String contacts) {
        this.contacts = contacts;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Education getEducation() {
        return education;
    }

    public void setEducation(Education education) {
        this.education = education;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public City getCity() {
        return city;
    }

    public TypeOfEmployment getTypeOfEmployment() {
        return typeOfEmployment;
    }

    public void setTypeOfEmployment(TypeOfEmployment typeOfEmployment) {
        this.typeOfEmployment = typeOfEmployment;
    }

    public Experience getExperience() {
        return experience;
    }

    public void setExperience(Experience experience) {
        this.experience = experience;
    }

    public List<VacancyFile> getVacancyFiles() {
        return vacancyFiles;
    }

    public void setResumeFiles(List<VacancyFile> vacancyFiles) {
        this.vacancyFiles = vacancyFiles;
        if (vacancyFiles != null) {
            for (VacancyFile vacancyFile : vacancyFiles) {
                vacancyFile.setVacancy(this);
            }
        }
    }
}
